package store

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
)

type ISTORE struct {
	base.Index8Instruction
}

func (self *ISTORE) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, self.Index)
}

type ISTORE_0 struct {
	base.NoOperandsInstruction
}

func (self *ISTORE_0) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 0)
}

type ISTORE_1 struct {
	base.NoOperandsInstruction
}

func (self *ISTORE_1) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 1)
}

type ISTORE_2 struct {
	base.NoOperandsInstruction
}

func (self *ISTORE_2) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 2)
}

type ISTORE_3 struct {
	base.NoOperandsInstruction
}

func (self *ISTORE_3) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 3)
}

func _istore(frame *rtda.JFrame, index uint) {
	val := frame.OperandStack().PopInt()
	frame.LocalVars().SetInt(index, val)
}
